using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Runtime.Serialization;
using System.Collections;
using System.Data;
using System.ComponentModel;
using System.Data.OracleClient;
using WPFExcelReport.Helpers;
using WPFExcelReport.Controls;
namespace WPFExcelReport
{
    public partial class VFSFARBEN
    {
        public DataRow Convert2FSFARBEN(DataRow dwInput, string ITXDBVERSION, bool IsConvert = false)
        {
            DataSet SResult = new DataSet();
            SResult = QueryFSFARBEN(dwInput, 0);
            DataRow dwReturn = null;
            if (SResult.Tables[0].Rows.Count > 0)
            {
                dwReturn = SResult.Tables[0].Rows[0];
            }
            else
            {
                dwReturn = SResult.Tables[0].NewRow();
            }
            switch (ITXDBVERSION)
            {
                case "YGR":
                    #region=========
         dwReturn["FSFMANDANT"] = " ".PadRight(2 ); 
         dwReturn["FSFART"] = " ".PadRight(20 ); 
         dwReturn["FSFVAR"] = " ".PadRight(2 ); 
         dwReturn["FSFFARBE"] = " ".PadRight(10 ); 
         dwReturn["FSFAENZL"] = " ".PadRight(0 ); 
         dwReturn["FSFAENB"] = " ".PadRight(8 ); 
         dwReturn["FSFAEND"] = " ".PadRight(0 ); 
         dwReturn["FSFNEUB"] = " ".PadRight(8 ); 
         dwReturn["FSFNEUD"] = " ".PadRight(0 ); 
         dwReturn["FSFABEZ"] = " ".PadRight(40 ); 
         dwReturn["FSFFBEZ"] = " ".PadRight(20 ); 
         dwReturn["FSFFKART"] = " ".PadRight(10 ); 
         dwReturn["FSFPRUEFGRP"] = " ".PadRight(1 ); 
         dwReturn["FSFPRGRP"] = " ".PadRight(1 ); 
         dwReturn["FSFPREIS"] = " ".PadRight(0 ); 
         dwReturn["FSFZUABPR"] = " ".PadRight(0 ); 
         dwReturn["FSFZUABAB"] = " ".PadRight(0 ); 
         dwReturn["FSFZUABVH"] = " ".PadRight(0 ); 
         dwReturn["FSFZUABAK"] = " ".PadRight(0 ); 
         dwReturn["FSFZUABKU"] = " ".PadRight(0 ); 
         dwReturn["FSFZUABPROZ"] = " ".PadRight(1 ); 
         dwReturn["FSFSTAKZ"] = " ".PadRight(1 ); 
         dwReturn["FSFSFKZ"] = " ".PadRight(1 ); 
         dwReturn["FSFMUNR"] = " ".PadRight(15 ); 
         dwReturn["FSFMBEZ"] = " ".PadRight(30 ); 
         dwReturn["FSFMAUFBKZ"] = " ".PadRight(1 ); 
         dwReturn["FSFMLO"] = " ".PadRight(2 ); 
         dwReturn["FSFMLB"] = " ".PadRight(2 ); 
         dwReturn["FSFMLP"] = " ".PadRight(8 ); 
         dwReturn["FSFAFARB"] = " ".PadRight(10 ); 
         dwReturn["FSFSPERRGR"] = " ".PadRight(2 ); 
         dwReturn["FSFSPDATUM"] = " ".PadRight(0 ); 
         dwReturn["FSFAVDATUM"] = " ".PadRight(0 ); 
         dwReturn["FSFARTKZ"] = " ".PadRight(1 ); 
         dwReturn["FSFFILLER"] = " ".PadRight(62 ); 
                    #endregion
                    break;
                case "JLT":

                    break;
                default:

                    break;
            }
            if (IsConvert)
            {
                foreach (DataColumn cm in dwInput.Table.Columns)
                {
                    if (dwInput[cm.ColumnName].ToString() == "")
                        continue;
                    if (dwReturn.Table.Columns.Contains(cm.ColumnName))
                    {
                        dwReturn[cm.ColumnName] = dwInput[cm.ColumnName];
                    }
                }
            }
            return dwReturn;
        }
        public void MapFSFARBEN(ref DataRow dwLocal, DataRow dwData)
        {
            BlindMap(ref dwLocal, dwData);
        }
        public void SaveFSFARBEN(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            DataSet setResult = new DataSet();
            DataTable tbLocal = null;
            DataRow dwLocal = null;
            bool flgExist = false;
            setResult = QueryFSFARBEN(dwData);
            if (setResult.Tables.Count > 0)
            {
                tbLocal = setResult.Tables[0];
                if (tbLocal.Rows.Count > 0)
                {
                    flgExist = true;
                    dwLocal = tbLocal.Rows[0];
                }
                else
                {
                    dwLocal = tbLocal.NewRow();
                }
            }
            MapFSFARBEN(ref dwLocal, dwData);

            if (!flgExist)
            {

                InsertFSFARBEN(dwLocal, ITXDBVERSION);
            }
            UpdateFSFARBEN(dwLocal);
        }
        public void InsertFSFARBEN(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            OracleCommand or1;
            or1 = OracleDB.CreateCommand();
            switch (ITXDBVERSION)
            {
                case "YGR":
                    or1.CommandText = "INSERT INTO FSFARBEN(VAKBMANDANT, VAKBKOLL, VAKBART, VAKBKUNDNR, VAKBFARBE, VAKBKDARTNR, VAKBKDARTBEZ, VAKBKDFARBNR, VAKBANDRUCK, VAKBMEGEW, VAKBMENGEH, VAKBGEWVON, VAKBGEWBIS, VAKBGEWCA, VAKBGEWFKT, VAKBGEWGRP, VAKBMEGFKT, VAKBMEGGRP, VAKBAENDZL, VAKBAENDBEN, VAKBAENDDAT, VAKBNEUBEN, VAKBNEUDAT, VAKBFILLER)"
                        + " VALUES (:VAKBMANDANT, :VAKBKOLL, :VAKBART, :VAKBKUNDNR, :VAKBFARBE, '                         ', '                         ', '                             ', ' ', '   ', '   ', 0, 0, ' ', '000000000000', ' ', '000000000000', ' ', 0, '        ', '000000', '        ', '      ', '                                          ')";
                    or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                //VAFMANDANT VAFKOLL VAFART VAFFARBE VAFBEZ VAFFFARBE

            }
            
            Connect2Proxy(or1);
        }
        public DataSet QueryFSFARBEN(DataRow dwData, int option = 1)
        {
            DataSet Return;
            DataSet Result = new DataSet();
            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 0:
                    or1.CommandText = "SELECT * FROM FSFARBEN WHERE  ROWNUM<2 ";
                    break;
              
                case 99:
                    or1.CommandText = "SELECT * FROM FSFARBEN  WHERE ROWNUM<50";
                    break;
                default:
                    break;
            }
            Result = Connect2Proxy(or1);
            if (Result.Tables.Count > 0)
                Result.Tables[0].TableName = "FSFARBEN";
            Return = Result;
            return Return;
        }
        public void DeleteFSFARBEN(DataRow dwData, int option = 1)
        {

            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    or1.CommandText = "DELETE FROM FSFARBEN   WHERE  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                     or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                default:
                    break;
            }
            Connect2Proxy(or1);
        } 
      
        public void UpdateFSFARBEN(DataRow dwData, string ITXDBVERSION = "50.24", int option = 1)
        {
            OracleCommand or1;
            DataSet Result = new DataSet();
            or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    #region====Command==== 
                    or1.CommandText = "UPDATE FSFARBEN SET "
                    +"FSFMANDANT= :FSFMANDANT,"
                    +"FSFART= :FSFART,"
                    +"FSFVAR= :FSFVAR,"
                    +"FSFFARBE= :FSFFARBE,"
                    +"FSFAENZL= :FSFAENZL,"
                    +"FSFAENB= :FSFAENB,"
                    +"FSFAEND= :FSFAEND,"
                    +"FSFNEUB= :FSFNEUB,"
                    +"FSFNEUD= :FSFNEUD,"
                    +"FSFABEZ= :FSFABEZ,"
                    +"FSFFBEZ= :FSFFBEZ,"
                    +"FSFFKART= :FSFFKART,"
                    +"FSFPRUEFGRP= :FSFPRUEFGRP,"
                    +"FSFPRGRP= :FSFPRGRP,"
                    +"FSFPREIS= :FSFPREIS,"
                    +"FSFZUABPR= :FSFZUABPR,"
                    +"FSFZUABAB= :FSFZUABAB,"
                    +"FSFZUABVH= :FSFZUABVH,"
                    +"FSFZUABAK= :FSFZUABAK,"
                    +"FSFZUABKU= :FSFZUABKU,"
                    +"FSFZUABPROZ= :FSFZUABPROZ,"
                    +"FSFSTAKZ= :FSFSTAKZ,"
                    +"FSFSFKZ= :FSFSFKZ,"
                    +"FSFMUNR= :FSFMUNR,"
                    +"FSFMBEZ= :FSFMBEZ,"
                    +"FSFMAUFBKZ= :FSFMAUFBKZ,"
                    +"FSFMLO= :FSFMLO,"
                    +"FSFMLB= :FSFMLB,"
                    +"FSFMLP= :FSFMLP,"
                    +"FSFAFARB= :FSFAFARB,"
                    +"FSFSPERRGR= :FSFSPERRGR,"
                    +"FSFSPDATUM= :FSFSPDATUM,"
                    +"FSFAVDATUM= :FSFAVDATUM,"
                    +"FSFARTKZ= :FSFARTKZ,"
                    +"FSFFILLER= :FSFFILLER,"
                        + " WHERE  "
                        + "  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                    #endregion

                    #region====Parameters====
          or1.Parameters.Add("FSFMANDANT", OracleType.NVarChar).Value = dwData["FSFMANDANT"].ToString(); 
          or1.Parameters.Add("FSFART", OracleType.NVarChar).Value = dwData["FSFART"].ToString(); 
          or1.Parameters.Add("FSFVAR", OracleType.NVarChar).Value = dwData["FSFVAR"].ToString(); 
          or1.Parameters.Add("FSFFARBE", OracleType.NVarChar).Value = dwData["FSFFARBE"].ToString(); 
          or1.Parameters.Add("FSFAENZL", OracleType.NVarChar).Value = dwData["FSFAENZL"].ToString(); 
          or1.Parameters.Add("FSFAENB", OracleType.NVarChar).Value = dwData["FSFAENB"].ToString(); 
          or1.Parameters.Add("FSFAEND", OracleType.NVarChar).Value = dwData["FSFAEND"].ToString(); 
          or1.Parameters.Add("FSFNEUB", OracleType.NVarChar).Value = dwData["FSFNEUB"].ToString(); 
          or1.Parameters.Add("FSFNEUD", OracleType.NVarChar).Value = dwData["FSFNEUD"].ToString(); 
          or1.Parameters.Add("FSFABEZ", OracleType.NVarChar).Value = dwData["FSFABEZ"].ToString(); 
          or1.Parameters.Add("FSFFBEZ", OracleType.NVarChar).Value = dwData["FSFFBEZ"].ToString(); 
          or1.Parameters.Add("FSFFKART", OracleType.NVarChar).Value = dwData["FSFFKART"].ToString(); 
          or1.Parameters.Add("FSFPRUEFGRP", OracleType.NVarChar).Value = dwData["FSFPRUEFGRP"].ToString(); 
          or1.Parameters.Add("FSFPRGRP", OracleType.NVarChar).Value = dwData["FSFPRGRP"].ToString(); 
          or1.Parameters.Add("FSFPREIS", OracleType.NVarChar).Value = dwData["FSFPREIS"].ToString(); 
          or1.Parameters.Add("FSFZUABPR", OracleType.NVarChar).Value = dwData["FSFZUABPR"].ToString(); 
          or1.Parameters.Add("FSFZUABAB", OracleType.NVarChar).Value = dwData["FSFZUABAB"].ToString(); 
          or1.Parameters.Add("FSFZUABVH", OracleType.NVarChar).Value = dwData["FSFZUABVH"].ToString(); 
          or1.Parameters.Add("FSFZUABAK", OracleType.NVarChar).Value = dwData["FSFZUABAK"].ToString(); 
          or1.Parameters.Add("FSFZUABKU", OracleType.NVarChar).Value = dwData["FSFZUABKU"].ToString(); 
          or1.Parameters.Add("FSFZUABPROZ", OracleType.NVarChar).Value = dwData["FSFZUABPROZ"].ToString(); 
          or1.Parameters.Add("FSFSTAKZ", OracleType.NVarChar).Value = dwData["FSFSTAKZ"].ToString(); 
          or1.Parameters.Add("FSFSFKZ", OracleType.NVarChar).Value = dwData["FSFSFKZ"].ToString(); 
          or1.Parameters.Add("FSFMUNR", OracleType.NVarChar).Value = dwData["FSFMUNR"].ToString(); 
          or1.Parameters.Add("FSFMBEZ", OracleType.NVarChar).Value = dwData["FSFMBEZ"].ToString(); 
          or1.Parameters.Add("FSFMAUFBKZ", OracleType.NVarChar).Value = dwData["FSFMAUFBKZ"].ToString(); 
          or1.Parameters.Add("FSFMLO", OracleType.NVarChar).Value = dwData["FSFMLO"].ToString(); 
          or1.Parameters.Add("FSFMLB", OracleType.NVarChar).Value = dwData["FSFMLB"].ToString(); 
          or1.Parameters.Add("FSFMLP", OracleType.NVarChar).Value = dwData["FSFMLP"].ToString(); 
          or1.Parameters.Add("FSFAFARB", OracleType.NVarChar).Value = dwData["FSFAFARB"].ToString(); 
          or1.Parameters.Add("FSFSPERRGR", OracleType.NVarChar).Value = dwData["FSFSPERRGR"].ToString(); 
          or1.Parameters.Add("FSFSPDATUM", OracleType.NVarChar).Value = dwData["FSFSPDATUM"].ToString(); 
          or1.Parameters.Add("FSFAVDATUM", OracleType.NVarChar).Value = dwData["FSFAVDATUM"].ToString(); 
          or1.Parameters.Add("FSFARTKZ", OracleType.NVarChar).Value = dwData["FSFARTKZ"].ToString(); 
          or1.Parameters.Add("FSFFILLER", OracleType.NVarChar).Value = dwData["FSFFILLER"].ToString(); 
                    #endregion
                    break; 
                default:
                    break;
            }


            Connect2Proxy(or1);
        }
    }
}
